from flask import Flask
from flask import Response, json
from flask import request
import requests

app = Flask(__name__)

app.config.from_object('config')

handers = app.config['HANDERS']


def registry():
    data = {
        "registryGroup": app.config['REGISTRYGROUP'],
        "registryKey": app.config['REGISTRYKEY'],
        "registryValue": app.config['REGISTRYVALUE'],
    }
    response = requests.post(url=app.config['SERVER_HTTP'], data=data, handers=handers)
    response.encoding = 'utf-8'
    info = json.loads(response)
    print(info)


def callback(id, time, code=200, msg=None):
    data = [
        {
            "logId": id,
            "logDateTim": time,
            "executeResult": {
                "code": code,
                "msg": msg
            }
        }
    ]
    response = requests.post(url=app.config['SERVER_HTTP'], data=data, handers=handers)
    response.encoding = 'utf-8'
    info = json.loads(response)
    return info


@app.route('/')
def hello_world():
    return 'Hello World!'


@app.route('/beat')
def beat():
    print(request.method)
    return Response(
        json.dumps(
            {
                "code": 200,
                "msg": None,
            }
        )
    )


@app.route('/idleBeat')
def idleBeat():
    pass


@app.route('/run')
def run():
    pass


@app.route('/kill')
def kill():
    pass


@app.route('/kill')
def kill():
    pass


if __name__ == '__main__':
    registry()
    app.run()
